import cv2
import numpy as np
img = cv2.imread(r"/\images\005.jpeg")

height = img.shape[0]
width = img.shape[1]
ksize = (5, 5) # 卷积核
dsize = (width, height)

# 均值滤波
img1 = cv2.blur(img, ksize)

# 高斯滤波
sigmaX = 0.3 * ((width - 1) * 0.5 - 1) + 0.8 # x方向上的权重
sigmaY = 0.3 * ((height - 1) * 0.5 - 1) + 0.8 # y方向上的权重
img2 = cv2.GaussianBlur(img, ksize, sigmaX, None, sigmaY)

# 方框滤波
img3 = cv2.boxFilter(img, -1, ksize, normalize=False)
img4 = cv2.boxFilter(img, -1, ksize, normalize=True)

# 中值滤波
img5 = cv2.medianBlur(img, 5)

# 双边滤波
img6 = cv2.bilateralFilter(img, 20, 100, 100)
pic = [("img", img), ("img1", img1), ("img2", img2),
       ("img3", img3), ("img4", img4), ("img5", img5),
       ("img6", img6)]

for name, val in pic:
    cv2.imshow(name, val)
    key = cv2.waitKey(5000)
    if key == 27:
        break
cv2.destroyAllWindows()
